package com.smartleanx.module.hrm.dal.mysql.esign;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.smartleanx.framework.common.pojo.PageResult;
import com.smartleanx.framework.mybatis.core.mapper.BaseMapperX;
import com.smartleanx.module.hrm.service.esign.temp.param.HrmEContractTaskParam;
import com.smartleanx.module.hrm.service.esign.temp.param.HrmEContractTempParam;
import com.smartleanx.module.hrm.service.esign.temp.po.HrmEContractTask;
import com.smartleanx.module.hrm.service.esign.temp.po.HrmEContractTemp;
import com.smartleanx.module.hrm.service.esign.temp.result.HrmETaskListResult;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * e签宝合同签署Mapper
 *
 * @author xzq
 * @since 2025-07-07 16:04:49
 */
@Mapper
public interface HrmEContractTaskMapper extends BaseMapperX<HrmEContractTask> {


    default PageResult<HrmEContractTask> getTaskPage(HrmEContractTaskParam param, List<Long> taskIds){

        LambdaQueryWrapper<HrmEContractTask> wrapperX = new LambdaQueryWrapper<>();
        wrapperX.eq(HrmEContractTask::getDataStatus,1);
        wrapperX.eq(param.getTaskStatus()!= null,HrmEContractTask::getTaskStatus,param.getTaskStatus());
        wrapperX.eq(StrUtil.isNotBlank(param.getContractName()),HrmEContractTask::getContractName,param.getContractName());
        wrapperX.eq(StrUtil.isNotBlank(param.getContractCode()),HrmEContractTask::getContractCode,param.getContractCode());
        wrapperX.eq(StrUtil.isNotBlank(param.getCreateUser()),HrmEContractTask::getCreator,param.getCreateUser());
        wrapperX.eq(param.getApprovalStatus()!= null,HrmEContractTask::getApprovalStatus,param.getApprovalStatus());
        wrapperX.in(CollUtil.isNotEmpty(taskIds),HrmEContractTask::getId,taskIds);

        if(param.getCreateTime()!=null && param.getCreateTime().length>0){
            wrapperX.between(HrmEContractTask::getCreateTime,param.getCreateTime()[0],param.getCreateTime()[1]);
//            wrapperX.lt(HrmEContractTask::getCreateTime,param.getCreateTime()[0]);
//            wrapperX.gt(HrmEContractTask::getCreateTime,param.getCreateTime()[1]);
        }
        if(param.getEffectiveDuration()!=null && param.getEffectiveDuration().length>0){
            wrapperX.between(HrmEContractTask::getEffectiveDuration,param.getEffectiveDuration()[0],param.getEffectiveDuration()[1]);
//            wrapperX.lt(HrmEContractTask::getEffectiveDuration,param.getEffectiveDuration()[0]);
//            wrapperX.gt(HrmEContractTask::getEffectiveDuration,param.getEffectiveDuration()[1]);
        }

        return selectPage(param, wrapperX);
    }

    Integer getTaskCountSql(@Param("param") HrmEContractTaskParam param);

    List<HrmETaskListResult> getTaskPageSql(@Param("param") HrmEContractTaskParam param);

    Integer getTaskCountSqlApp(@Param("param") HrmEContractTaskParam param);

    List<HrmETaskListResult> getTaskPageSqlApp(@Param("param") HrmEContractTaskParam param);
}
